package com.team.order.api.factory;

import com.team.common.core.web.domain.AjaxResult;
import com.team.order.api.RemoteAdminOrderService;
import com.team.order.api.domain.OrderSubmitDTO;
import com.team.order.api.domain.RepairReservationDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 订单服务降级处理
 * @author 梁国瑞
 * @version 1.0
 */
@Slf4j
@Component
public class RemoteAdminOrderFallbackFactory implements FallbackFactory<RemoteAdminOrderService> {

    @Override
    public RemoteAdminOrderService create(Throwable throwable) {
        log.error("订单服务调用失败：{}", throwable.getMessage());
        
        return new RemoteAdminOrderService() {
            
            // ==================== 订单管理接口 ====================
            
            @Override
            public AjaxResult getOrderList(String orderDTO) {
                return AjaxResult.error("获取订单列表失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult getOrderInfo(Long id) {
                return AjaxResult.error("获取订单详情失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult addOrder(String order) {
                return AjaxResult.error("新增订单失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult editOrder(String order) {
                return AjaxResult.error("修改订单失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult removeOrder(Long[] ids) {
                return AjaxResult.error("删除订单失败：" + throwable.getMessage());
            }
            
            // ==================== 用户订单接口 ====================
            
            @Override
            public AjaxResult submitOrder(OrderSubmitDTO orderSubmitDTO) {
                return AjaxResult.error("提交订单失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult payOrder(String orderNo) {
                return AjaxResult.error("订单支付失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult queryPayStatus(String orderNo) {
                return AjaxResult.error("查询支付状态失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult cancelPay(Long orderId) {
                return AjaxResult.error("取消支付失败：" + throwable.getMessage());
            }
            
            // ==================== 维修预约接口 ====================
            
            @Override
            public AjaxResult addRepair(RepairReservationDTO repairReservation) {
                return AjaxResult.error("创建维修预约失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult updateRepair(RepairReservationDTO repairReservation) {
                return AjaxResult.error("修改维修预约失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult getReservationList(Long merchantId, String status) {
                return AjaxResult.error("查询维修预约列表失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult updateReservationStatus(Long reservationId, String status) {
                return AjaxResult.error("更新维修预约状态失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult getReservationDetail(Long reservationId) {
                return AjaxResult.error("获取维修预约详情失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult cancelReservation(Long reservationId) {
                return AjaxResult.error("取消维修预约失败：" + throwable.getMessage());
            }
            
            // ==================== 订单统计接口 ====================
            
            @Override
            public AjaxResult getOrderStatisticsByRegion() {
                return AjaxResult.error("获取区域订单统计失败：" + throwable.getMessage());
            }
            
            // ==================== 模拟支付接口 ====================
            
            @Override
            public AjaxResult simulatePaymentSuccess(String orderNo) {
                return AjaxResult.error("模拟支付成功失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult simulatePaymentFail(String orderNo) {
                return AjaxResult.error("模拟支付失败操作异常：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult queryPaymentStatus(String orderNo) {
                return AjaxResult.error("查询支付状态失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult refund(String orderNo, String amount) {
                return AjaxResult.error("模拟退款失败：" + throwable.getMessage());
            }
            
            @Override
            public AjaxResult clearAllData() {
                return AjaxResult.error("清除模拟支付数据失败：" + throwable.getMessage());
            }
            
            // ==================== 模拟支付回调接口 ====================
            
            @Override
            public String paymentSuccessCallback(String orderNo) {
                log.error("支付成功回调处理异常，订单号：{}", orderNo, throwable);
                return "FAIL";
            }
            
            @Override
            public String paymentFailCallback(String orderNo) {
                log.error("支付失败回调处理异常，订单号：{}", orderNo, throwable);
                return "FAIL";
            }
            
            @Override
            public String alipaySuccessCallback(String orderNo) {
                log.error("支付宝支付成功回调处理异常，订单号：{}", orderNo, throwable);
                return "FAIL";
            }
        };
    }
} 